<?php
require 'model-db-connection/config.php';
$config = require 'model-db-connection/qrc_conf.properties.php';
$searchCondition = $_GET['search_condition'];
$projectCodeSearch = $_GET['projectCodeSearch'];
$projectNameSearch = $_GET['projectNameSearch'];
$projectTypeSearch = $_GET['projectTypeSearch'];
$projectStatusSearch = $_GET['projectStatusSearch'];
$projectOwnerSearch = $_GET['projectOwnerSearch'];
$projectCustomerSearch = $_GET['projectCustomerSearch'];
$startSearchDate = $_GET['startSearchDate'];
$endSearchDate = $_GET['endSearchDate'];
?>
<div class="widget">
    <div class="widget-head">
        <h4 class="heading">Project (โครงการ)</h4>
        <a href="#modal-login" data-toggle="modal" class="btn btn-xs btn-inverse pull-right" id="new_project_btn" style="margin-top: 6px;"><i class="fa fa-plus fa-fw"></i> New Project</a>
        <div class="clearfix"></div>
    </div>
    <div class="widget-body innerAll inner-2x">
        <!-- Table -->
        <table class="footable table table-striped table-primary" id="dataTables-project">

            <!-- Table heading -->
            <thead>
                <tr>
                    <th data-class="expand" class="center">Project Code</th>
                    <th data-hide="phone,tablet">Customer Name</th>
                    <th data-hide="phone,tablet">Project Manager</th>
                    <th data-hide="phone,tablet">Project Foreman</th>
                    <th data-hide="phone,tablet">Supervisor Control</th>
                    <th data-hide="phone,tablet">Team Owner</th>
                    <th data-hide="phone,tablet">Quality Inspectors</th>
                    <th data-hide="phone,tablet">Address/Location</th>
                    <th data-hide="phone,tablet">Remark</th>
                    <th class="center">Project Name</th>
                    <th class="center">Project Status</th>
                    <th class="center">Project Owner</th>
                    <th class="center">Project Type</th>
                    <th class="center"></th>
                </tr>
            </thead>
            <!-- // Table heading END -->

            <!-- Table body -->
            <tbody>
                <?php
                if ($searchCondition == "search_all") {
                    $sqlSelectAllProjectRecord = "SELECT qp.project_code as project_code,"
                            . "qp.project_name as project_name,"
                            . "ps.project_status_name as project_status,"
                            . "po.project_owner_name as project_owner,"
                            . "pt.project_type_name as project_type,"
                            . "qcn.customer_name as customer_name,"
                            . "qp.project_manager as project_manager,"
                            . "qp.project_foreman as project_foreman,"
                            . "qp.supervisor_control as supervisor_control,"
                            . "qtb.tName as team_owner,"
                            . "qp.quality_inspectors as quality_inspectors,"
                            . "qp.project_remark as remark,"
                            . "qp.address_location as address_location"
                            . " FROM QRC_PROJECT qp"
                            . " LEFT JOIN PROJECT_STATUS ps ON qp.project_status = ps.project_status_id"
                            . " LEFT JOIN PROJECT_OWNER po ON qp.project_owner = po.project_owner_id"
                            . " LEFT JOIN PROJECT_TYPE pt on qp.project_type = pt.project_type_id"
                            . " LEFT JOIN QRC_CUSTOMER_NAME qcn on qp.customer_id = qcn.customer_id"
                            . " LEFT JOIN QRC_TEAM_BUILDER qtb ON qp.team_owner = qtb.tCode"
                            . " ORDER BY qp.created_date_time DESC;";
                } else {
                    $checkProjectCode = !empty($projectCodeSearch) ? " AND qp.project_code LIKE '%$projectCodeSearch%'" : "";
                    $checkProjectName = !empty($projectNameSearch) ? " AND qp.project_name LIKE '%$projectNameSearch%'" : "";
                    $checkProjectType = !empty($projectTypeSearch) ? " AND pt.project_type_id LIKE '$projectTypeSearch'" : "";
                    $checkProjectStatus = !empty($projectStatusSearch) ? " AND qp.project_status LIKE '$projectStatusSearch'" : "";
                    $checkProjectOwner = !empty($projectOwnerSearch) ? " AND qp.project_owner LIKE '$projectOwnerSearch'" : "";
                    $checkProjectCustomer = !empty($projectCustomerSearch) ? " AND qp.customer_id LIKE '$projectCustomerSearch'" : "";
                    $checkStartDate = !empty($startSearchDate) ? " AND qp.created_date_time BETWEEN '$startSearchDate' AND '$endSearchDate'" : "";
                    $sqlSelectAllProjectRecord = "SELECT qp.project_code as project_code,"
                            . "qp.project_name as project_name,"
                            . "ps.project_status_name as project_status,"
                            . "po.project_owner_name as project_owner,"
                            . "pt.project_type_name as project_type,"
                            . "pt.project_type_id as project_type_id,"
                            . "qcn.customer_name as customer_name,"
                            . "qp.project_manager as project_manager,"
                            . "qp.project_foreman as project_foreman,"
                            . "qp.supervisor_control as supervisor_control,"
                            . "qtb.tName as team_owner,"
                            . "qp.quality_inspectors as quality_inspectors,"
                            . "qp.project_remark as remark,"
                            . "qp.address_location as address_location"
                            . " FROM QRC_PROJECT qp"
                            . " LEFT JOIN PROJECT_STATUS ps ON qp.project_status = ps.project_status_id"
                            . " LEFT JOIN PROJECT_OWNER po ON qp.project_owner = po.project_owner_id"
                            . " LEFT JOIN PROJECT_TYPE pt on qp.project_type = pt.project_type_id"
                            . " LEFT JOIN QRC_CUSTOMER_NAME qcn on qp.customer_id = qcn.customer_id"
                            . " LEFT JOIN QRC_TEAM_BUILDER qtb ON qp.team_owner = qtb.tCode"
                            . " WHERE 1=1"
                            . $checkProjectCode
                            . $checkProjectName
                            . $checkProjectType
                            . $checkProjectStatus
                            . $checkProjectOwner
                            . $checkProjectCustomer
                            . $checkStartDate
                            . " ORDER BY qp.created_date_time DESC;";
                }
//                echo $sqlSelectAllProjectRecord;
                $sqlGetAllData = mysql_query($sqlSelectAllProjectRecord);
                if (mysql_num_rows($sqlGetAllData) >= 1) {
                    while ($row = mysql_fetch_assoc($sqlGetAllData)) {

                        echo '<tr class = "gradeX">';
                        echo '<td>' . $row['project_code'] . '</td>';
                        echo '<td>' . $row['customer_name'] . '</td>';
                        echo '<td>' . $row['project_manager'] . '</td>';
                        echo '<td>' . $row['project_foreman'] . '</td>';
                        echo '<td>' . $row['supervisor_control'] . '</td>';
                        echo '<td>' . $row['team_owner'] . '</td>';
                        $data = $row['quality_inspectors'];
                        $sqlSelectSeletedMembers = "SELECT memName FROM QRC_MEMBERS WHERE memID like '$data';";
                        $sqlGetQI = mysql_query($sqlSelectSeletedMembers);
                        $rows = mysql_fetch_assoc($sqlGetQI);
                        echo '<td>' . $rows['memName'] . '</td>';
                        echo '<td>' . $row['address_location'] . '</td>';
                        echo '<td>' . $row['remark'] . '</td>';
                        echo '<td class = "center">' . $row['project_name'] . '</td>';
                        echo '<td class = "center">' . $row['project_status'] . '</td>';
                        echo '<td class = "center">' . $row['project_owner'] . '</td>';
                        echo '<td class = "center">' . $row['project_type'] . '</td>';
                        echo '<td class = "center">';
                        echo '<a href = "#modal-login" data-toggle = "modal" class = "btn btn-primary" onclick=editProject("' . $row['project_code'] . '")><i class = "icon-document-line"></i> Edit</a>';
                        echo '<button class = "btn btn-primary" style="margin-left: 5px" onclick=loadProjectOrder("' . $row['project_code'] . '","' . str_replace(' ', '_', $row['project_name']) . '")><i class = "icon-document-line"></i> Work Order</button>';
                        echo '<button class = "btn btn-danger" style="margin-left: 5px" onclick=deleteProject("' . $row['project_code'] . '")><i class = "fa fa-trash-o"></i> Delete</button>';

                        echo '</td>';
                        echo '</tr>';
                    }
                }
                ?>
            </tbody>
            <!-- // Table body END -->

        </table>
        <!-- // Table END -->

    </div>
</div>

<div class="modal fade" id="modal-login">

    <div class="modal-dialog">
        <div class="modal-content">

            <!-- Modal heading -->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h2 class="modal-title">Project Create/Edit</h2>
            </div>
            <!-- // Modal heading END -->

            <!-- Modal body -->
            <div class="modal-body">
                <div class="innerAll">
                    <div class="innerLR">
                        <form class="form-horizontal" role="form" id="project_form">
                            <div class="form-group">
                                <label class="col-sm-6 control-label">Project Code :</label>
                                <div class="col-sm-6">
                                    <?php
                                    $sqlSelectMaxValue = "SELECT count(*) as total FROM QRC_PROJECT";
                                    $resultSet = mysql_query($sqlSelectMaxValue);
                                    $row = mysql_fetch_assoc($resultSet);
                                    if ($row['total'] == 0) {
                                        echo '<p class="form-control-static" id="projectCode">P0001</p>';
                                        echo '<input type="hidden" name="project_code" id="project_code" value="P0001"/>';
                                    } else {
                                        $sqlSelectCodeValue = "SELECT max(project_code) as code FROM QRC_PROJECT";
                                        $resultSets = mysql_query($sqlSelectCodeValue);
                                        $row = mysql_fetch_assoc($resultSets);
                                        $prefix = "P";
                                        $pieces = explode("P", $row[code]);
                                        if (count(intval($pieces[1])) == 1) {
                                            $strResult = $prefix . "000" . (intval($pieces[1] + 1));
                                        } else if (count(intval($pieces[1])) == 2) {
                                            $strResult = $prefix . "00" . (intval($pieces[1] + 1));
                                        } else if (count(intval($pieces[1])) == 3) {
                                            $strResult = $prefix . "0" . (intval($pieces[1] + 1));
                                        } else {
                                            $strResult = $prefix . (intval($pieces[1] + 1));
                                        }
                                        echo '<p class="form-control-static" id="projectCode">' . $strResult . '</p>';
                                        echo '<p class="form-control-static" id="projectCodeShowForEdit"></p>';
                                        echo '<input type="hidden" name="project_code" id="project_code" value="' . $strResult . '"/>';
                                    }
                                    ?>

                                </div>
                            </div>
                            <div class="form-group">
                                <label for="project_name" class="col-sm-6 control-label">Project Name (โครงการ)* :</label>
                                <div class="col-sm-6" id="project_name_div">
                                    <input type="text" class="form-control" id="project_name" name="project_name">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="project_type" class="col-sm-6 control-label">Project Type (ประเภทโครงการ)* :</label>
                                <div class="col-sm-6">
                                    <div class="btn-group" id="project_type_div">
                                        <select class="form-control" id="project_type_select" name="project_type">
                                            <option value="0">---Please select---</option>
                                            <?php
                                            $sqlSelectProjectType = "SELECT * FROM PROJECT_TYPE;";
                                            $resultSet = mysql_query($sqlSelectProjectType);
                                            while ($row = mysql_fetch_array($resultSet)) {
                                                echo '<option value="' . $row['project_type_id'] . '">' . $row['project_type_name'] . '</option>';
                                            }
                                            ?>                                           
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="project_type" class="col-sm-6 control-label">Project Status (สถานะโครงการ)* :</label>
                                <div class="col-sm-6">
                                    <div class="btn-group" id="project_status_div">
                                        <select class="form-control" id="project_status_select" name="project_status">
                                            <option value="0">---Please select---</option>
                                            <?php
                                            $sqlSelectProjectType = "SELECT * FROM PROJECT_STATUS;";
                                            $resultSet = mysql_query($sqlSelectProjectType);
                                            while ($row = mysql_fetch_array($resultSet)) {
                                                echo '<option value="' . $row['project_status_id'] . '">' . $row['project_status_name'] . '</option>';
                                            }
                                            ?>                                           
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="project_type" class="col-sm-6 control-label">Project Owner (เจ้าของโครงการ)* :</label>
                                <div class="col-sm-6">
                                    <div class="btn-group" id="project_owner_div">
                                        <select class="form-control" id="project_owner_select" name="project_owner">
                                            <option value="0">---Please select---</option>
                                            <?php
                                            $sqlSelectProjectType = "SELECT * FROM PROJECT_OWNER;";
                                            $resultSet = mysql_query($sqlSelectProjectType);
                                            while ($row = mysql_fetch_array($resultSet)) {
                                                echo '<option value="' . $row['project_owner_id'] . '">' . $row['project_owner_name'] . '</option>';
                                            }
                                            ?>                                           
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="project_type" class="col-sm-6 control-label">Customer Name (ชื่อลูกค้า)* :</label>
                                <div class="col-sm-6">
                                    <div class="btn-group" id="project_customer_div">
                                        <select class="form-control" id="project_customer_select" name="project_customer">
                                            <option value="0">---Please select---</option>
                                            <?php
                                            $sqlSelectProjectType = "SELECT * FROM QRC_CUSTOMER_NAME;";
                                            $resultSet = mysql_query($sqlSelectProjectType);
                                            while ($row = mysql_fetch_array($resultSet)) {
                                                echo '<option value="' . $row['customer_id'] . '">' . $row['customer_name'] . '</option>';
                                            }
                                            ?>                                           
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="project_manager" class="col-sm-6 control-label">Project Manager (ผู้ดูแลโครงการ) :</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" id="project_manager" name="project_manager">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="project_foreman" class="col-sm-6 control-label">Project Foreman(ผู้ควบคุมงานของโครงการ) :</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" id="project_foreman" name="project_foreman">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="supervisor_control" class="col-sm-6 control-label">Supervisor Control (ผู้ควบคุมงานของลูกค้า) :</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" id="supervisor_control" name="supervisor_control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="project_supervisor_tel" class="col-sm-6 control-label">Team Owner (ทีมที่ดูแลโครงการ) :</label>
                                <div class="col-sm-6">
                                    <select class="form-control" id="team_owner" name="team_owner">
                                        <option value="0">---Please select---</option>
                                        <?php
                                        $sqlSelectProjectType = "SELECT * FROM QRC_TEAM_BUILDER;";
                                        $resultSet = mysql_query($sqlSelectProjectType);
                                        while ($row = mysql_fetch_array($resultSet)) {
                                            echo '<option value="' . $row['tCode'] . '">' . $row['tName'] . '</option>';
                                        }
                                        ?>                                           
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="qa_inspectors" class="col-sm-6 control-label">Quality Inspectors (ผู้ตรวจสอบคุณภาพ) :</label>
                                <div class="col-sm-6">
                                    <select class="form-control" id="qa_inspectors" name="qa_inspectors">
                                        <option value="0">---Please select---</option>
                                        <?php
                                        $sqlSelectProjectType = "SELECT * FROM QRC_MEMBERS WHERE memRole='60001';";
                                        $resultSet = mysql_query($sqlSelectProjectType);
                                        while ($row = mysql_fetch_array($resultSet)) {
                                            echo '<option value="' . $row['memID'] . '">' . $row['memName'] . '</option>';
                                        }
                                        ?>                                           
                                    </select>
                                </div>
                            </div>
                            <div class="form-group" id="createDate">
                                <label for="created_date" class="col-sm-6 control-label">Created Date (วันที่สร้างโปรเจค) :</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" id="created_date" disabled="true">
                                </div>
                            </div>
                            <div class="form-group" id="lastUpdate">
                                <label for="last_update" class="col-sm-6 control-label">Last update (วันที่แก้ไขล่าสุด) :</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" id="last_update" disabled="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="last_update" class="col-sm-6 control-label">Address/Location :</label>
                                <div class="col-sm-6">
                                    <input type="text" class="form-control" id="address_location" name="address_location" val="">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="project_remark" class="col-sm-6 control-label">Remark :</label>
                                <div class="col-sm-6">
                                    <textarea rows="4" cols="30" id="project_remark" name="project_remark"></textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <button type="button" class="btn btn-primary btn-block" id="save_project_detail"><i class="fa fa-lock"></i> บันทึก</button>
                                <button type="button" class="btn btn-default btn-block" id="close-modal-btn"><i class="fa fa-times"></i> ปิด</button>
                            </div>

                        </form>
                    </div>
                </div>
            </div>
            <!-- // Modal body END -->

        </div>
    </div>

</div>
<script src="assets/components/common/tables/responsive/assets/lib/js/footable.min.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/common/tables/responsive/assets/custom/js/tables-responsive-footable.init.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/modules/admin/notifications/gritter/assets/lib/js/jquery.gritter.min.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/modules/admin/modals/assets/js/bootbox.min.js?v=v1.0.2&sv=v0.0.1"></script>
<script type="text/javascript">
    var createOrEditState = "Create";
    $(document).ready(function() {
        $("#dataTables-project").dataTable();
        $("#link_to_project").click(function() {
            $(".about_project").show();
            $("#load_project_order").empty();
            $("#link_to_project_order").empty();
            $("#link_to_project").empty();
            $("#link_to_project").append("Project(โครงการ)");
        });
        $("#save_project_detail").click(function() {
            if ($("#project_name").val() == "") {
                $("#project_name_div").addClass("has-error");
            } else {
                $("#project_name_div").removeClass("has-error");
            }
            if ($("#project_type_select").val() == 0) {
                $("#project_type_div").addClass("has-error");
            } else {
                $("#project_type_div").removeClass("has-error");
            }

            if ($("#project_status_select").val() == 0) {
                $("#project_status_div").addClass("has-error");
            } else {
                $("#project_status_div").removeClass("has-error");
            }

            if ($("#project_owner_select").val() == 0) {
                $("#project_owner_div").addClass("has-error");
            } else {
                $("#project_owner_div").removeClass("has-error");
            }
            if ($("#project_customer_select").val() == 0) {
                $("#project_customer_div").addClass("has-error");
            } else {
                $("#project_customer_div").removeClass("has-error");
            }
            if ($("#project_name").val() != "" && $("#project_type_select").val() != 0 && $("#project_status_select").val() != 0 && $("#project_owner_select").val() != 0 && $("#project_customer_select").val() != 0) {
                $("#project_customer_div").removeClass("has-error");
                $("#project_owner_div").removeClass("has-error");
                $("#project_status_div").removeClass("has-error");
                $("#project_type_div").removeClass("has-error");
                $("#project_name_div").removeClass("has-error");
                if (createOrEditState == "Create") {
                    //Create state when click
                    var data = $("#project_form").serialize();
                    var jqxhr = $.post("model/SavingProject.php?" + data);
                    jqxhr.success(function(data) {
                        if (data == 1) {
                            $.gritter.add({
                                title: 'Success!',
                                text: "<?= $config['msg_save_success'] ?>"
                            });
                            $("#save_project_detail").hide();
                            disableFormObject();
                        } else {
                            alert("ไม่สามารถบันทึกได้");
                        }
                    });
                    jqxhr.error(function(data) {
                        window.location.replace("error.php?error_msg=" + data);
                    });
                } else {
                    //Update State when click
                    if ($("#project_remark").val() == "") {
                        alert("กรุณาใส่ Remark");
                    } else {
                        var data = $("#project_form").serialize();
                        var jqxhr = $.post("model/EditProject.php?" + data);
                        jqxhr.success(function(data) {
                            if (data == 1) {
                                $.gritter.add({
                                    title: 'Success!',
                                    text: "<?= $config['msg_edit_success'] ?>"
                                });
                                $("#save_project_detail").hide();
                                disableFormObject();
                            }
                        });
                        jqxhr.error(function(data) {
                            //alert("ไม่สามารถเชื่อมต่อกับ Server ได้");
                            window.location.replace("error.php?error_msg=" + data);
                        });
                    }
                }
            }

        });
        $("#new_project_btn").click(function() {
            setTimeout(function()
            {
                $("#project_status_select").val("30001");
            }
            , 500);

            clearAllField();
            var m_names = new Array("มกราคม", "กุมภาพันธ์", "มีนาคม",
                    "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน",
                    "ตุลาคม", "พฤศจิกายน", "ธันวาคม");
            var d = new Date();
            var curr_date = d.getDate();
            var curr_month = d.getMonth();
            var curr_year = d.getFullYear();
            $("#created_date").val(curr_date + " " + m_names[curr_month] + " " + (curr_year + 543));
            createOrEditState = "Create";
            $("#save_project_detail").show();
        });
        $("#close-modal-btn").click(function() {
            blockPage();
            $("#modal-login").modal('hide');
            setTimeout(function()
            {
                $("input").prop('disabled', false);
                $("select").prop('disabled', false);

                $("#load_project").load("ProjectPage.php?search_condition=search_all", function() {
                    $.unblockUI();
                });
                var projectCodeSearch = $("#project_code_search").val("");
                var projectNameSearch = $("#project_name_search").val("");
                var projectTypeSearch = $("#project_type_search").val("");
                var projectStatusSearch = $("#project_status_search").val("");
                var projectOwnerSearch = $("#project_owner_search").val("");
                var projectCustomerSearch = $("#project_customer_search").val("");
                var startSearchDate = $("#start_search_date").val("");
                var endSearchDate = $("#end_search_date").val("");
                clearAllField();
                $("#save_project_detail").show();
            }
            , 500);

        });
        function clearAllField() {
            var form = document.getElementById("project_form");
            form.reset();
        }
        function disableFormObject() {
            $("input").prop('disabled', true);
            $("select").prop('disabled', true);
            $("textarea").prop('disabled', true);
        }

    });
    function deleteProject(projectCode) {
        blockPage();
        var jqxhr = $.post("model/DeleteProject.php?project_code=" + projectCode);
        jqxhr.success(function(data) {
            $.unblockUI();
            if (data == 1) {
                setTimeout(function()
                {
                    blockPage();
                    $("#load_project").load("ProjectPage.php?search_condition=search_all", function() {
                        $.unblockUI();
                    });
                    var projectCodeSearch = $("#project_code_search").val("");
                    var projectNameSearch = $("#project_name_search").val("");
                    var projectTypeSearch = $("#project_type_search").val("");
                    var projectStatusSearch = $("#project_status_search").val("");
                    var projectOwnerSearch = $("#project_owner_search").val("");
                    var projectCustomerSearch = $("#project_customer_search").val("");
                    var startSearchDate = $("#start_search_date").val("");
                    var endSearchDate = $("#end_search_date").val("");
                    $.gritter.add({
                        title: 'Success!',
                        text: "<?= $config['msg_delete_success'] ?>"
                    });
                }
                , 500);
            } else {
                alert("ไม่สามารถลบข้อมูลได้");
            }
        });
        jqxhr.error(function(data) {
            window.location.replace("error.php?error_msg=" + data);
        });
    }
    function editProject(projectCode) {
        createOrEditState = "Edit";
        blockPage();
        var jqxhr = $.post("model/GetAllProjectForEdit.php?project_code=" + projectCode);
        jqxhr.success(function(data) {
            $.unblockUI();
            obj = JSON.parse(data);
            $("#projectCodeShowForEdit").html(obj.project_code);
            $("#projectCode").hide();
            $("#project_code").val(obj.project_code);
            $("#project_name").val(obj.project_name);
            $("#project_type_select").val(obj.project_type);
            $("#project_status_select").val(obj.project_status);
            $("#project_owner_select").val(obj.project_owner);
            $("#project_customer_select").val(obj.customer_name);
            $("#project_manager").val(obj.project_manager);
            $("#project_foreman").val(obj.project_foreman);
            $("#supervisor_control").val(obj.supervisor_control);
            $("#team_owner").val(obj.team_owner);
            $("#qa_inspectors").val(obj.quality_inspectors);
            $("#project_remark").val(obj.remark);
            $("#created_date").val(obj.created_date_time);
            $("#last_update").val(obj.updated_date_time);
            $("#address_location").val(obj.address_location);

        });
        jqxhr.error(function(data) {
            window.location.replace("error.php?error_msg=" + data);
        });
    }
    function loadProjectOrder(projectCode, projectName) {
        blockPage();
        $("#load_project_order").load("ProjectOrderPage.php?project_code=" + projectCode, function() {
            $.unblockUI();
        });
        $(".about_project").hide();
        $("#link_to_project_order").html(" -> " + projectName.replace("_", " "));
        $("#link_to_project").empty();
        $("#link_to_project").append('<a href="#">Project(โครงการ)</a>');
    }
    function blockPage() {
        $.blockUI({message: 'Operation in progress...', css: {
                border: 'none',
                padding: '15px',
                backgroundColor: '#000',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                opacity: .5,
                color: '#fff'
            }});
    }
</script>